package com.googlecode.animator.controller
{
	import com.googlecode.animator.data.markers.HideMarkerVO;
	import com.googlecode.animator.data.markers.KeyframeVO;
	import com.googlecode.animator.data.objects3d.Object3DVO;
	
	import flash.utils.Dictionary;
	
	import org.papervision3d.core.math.Number3D;
	import org.puremvc.as3.interfaces.INotification;
	
	public class TimelineScrubObjects3DCommand extends BaseCommand
	{
		override public function execute(notification:INotification):void
		{
			var time:int = notification.getBody() as int;
			var objects3D:Dictionary = settings.objects3D;

			for each(var VO:Object3DVO in objects3D)
			{
				var tweens:Array = ((VO as Object3DVO).clone() as Object3DVO).tweens;
				var currentTween:Number3D;

				if(tweens.length >= time)
				{
					currentTween = tweens[time];
						

				}else
				{
					currentTween = tweens[tweens.length-1];
				}

				if(currentTween != null)
				{
					settings.setPosObject3D(VO.name, currentTween.clone(), true);
				}
				
				// now do the hideMarkers
				
				var hideMarkers:Dictionary = VO.hideMarkers;
					
				settings.setObject3DVisible(VO.name, true);
				
				for each(var hm:HideMarkerVO in hideMarkers)
				{
					if(hm.begin <= time && hm.end >= time)
					
						settings.setObject3DVisible(VO.name, false);
						
					}
				}
				
			} 
		
	}
}